<?php

/***  DOCUMENTATION LAYER

Simple PHP Testing Script

Last Update: May 2007
	
DESCRIPTION
	brief description of script here
	
NOTES
		
***/

$_tx0 = microtime();

// Test Name
$test_name = 'test';

// Include Files
#require_once('path/fname.php');

// Variable Declarations
#$foo = 'bar';

$html = <<<HTML

<script type="text/javascript">
var user_is_found = 0;
</script>

HTML;

// Script
if ( 1 )
{
  if ( isset($_GET['u']) ) 
  {
    #print '<script type="text/javascript">alert("GET value: '.$_GET['u'].'")</script>';
  }
  
  // run db query
  if ( 1 )
  {
    $user_salt = md5(mt_rand(1,1000));
  }
  
  
  // update js script
  $html = <<<HTML

<script type="text/javascript">

function cx_hidden_input_field(name, value)
{
  var Obj = document.createElement("input");
  Obj.setAttribute("type", "hidden");
  Obj.setAttribute("name", name);
  Obj.setAttribute("value", value);
  return Obj;
}

// define salt
var user_salt = "$user_salt";

/* deprecated
var user_is_found = 1;
window.parent.set_is_found(user_is_found);
window.parent.set_salt(user_salt);
*/

// Define DOM Objects
var ParentDoc = parent.document;
var ParentLoginForm = ParentDoc.getElementById("outer_form");
var ParentHashForm = ParentDoc.getElementById("hash_form");

// Get user input data from parent doc
var parent_user = ParentLoginForm.user_name.value;
var parent_pw = ParentLoginForm.user_pw.value;

// Hash password (pseudo -- requires md5 script)
var hashed_pw = "md5(" + parent_pw + user_salt + ")";
//alert("password entered is: " + parent_pw); alert("hashing password --> new_password = " + new_password);

// Prepare and submit hash form
HashFormUserName = cx_hidden_input_field("user_name", parent_user);
HashFormPw = cx_hidden_input_field("hashed_password", hashed_pw);
ParentHashForm.appendChild(HashFormUserName);
ParentHashForm.appendChild(HashFormPw);
ParentHashForm.submit();

</script>

HTML;

  print $html;
  
}


// Footer
$_txn = microtime();
$stx = number_format(((substr($_txn,0,9)) + (substr($_txn,-10)) - (substr($_tx0,0,9)) - (substr($_tx0,-10))),4); 
echo "<h6>test '$test_name' complete in $stx s</h6>";

?>
